package com.geostar.gmp.scan;

import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.geostar.gmp.dao.IPc_IPDao;
import com.geostar.gmp.global.ConfigValue;
import com.geostar.gmp.model.Pc_ip;
import com.geostar.gmp.model.factory.SessionFactory;
import com.geostar.gmp.thread.GetPc_info_Job;
import com.geostar.gmp.thread.ThreadPoolManager;
import com.geostar.gmp.utils.ReadXMLUtils;

/**
 * 文件名:ScanJob.java 
 * 功能: 扫描任务开始 
 * 目前支持方法
 * --------------------------------------
 * 初始版本 作者: yesong 时间: Apr 3, 2014
 */
public class ScanJob implements Job {

	private static Logger logger = LoggerFactory.getLogger(ScanJob.class);
	
	private List<Pc_ip> pc_ipList ; // 初始化pc_ip集合
	
	private ThreadPoolManager tpm; // 线程池管理器
	
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		logger.info(">>>>>>>>>>>>>>>开始扫描<<<<<<<<<<<<<<<<");
		SqlSession session = null;
		session = SessionFactory.createSession();
		
		IPc_IPDao pcDao = session.getMapper(IPc_IPDao.class);
		this.pc_ipList = pcDao.findAllPc_ip();
		
		// 初始化线程池管理器
		int pool_num = pc_ipList!=null?pc_ipList.size():0;
		tpm = new ThreadPoolManager(pool_num);
		
		for (Pc_ip pc_ip : pc_ipList) {
			// 监控电脑信息JOB
			GetPc_info_Job job = new GetPc_info_Job();
			job.setPc_ip(pc_ip);
			tpm.fork(job);// 指派任务
		}
		tpm.join(); // 结果汇总
		
		
	}
}
